@(currentPage: Page[Good], currentOrderBy: Int, currentFilter: String)

@****************************************
* Helper generating navigation links    *
****************************************@
@link(newPage: Int, newOrderBy: Option[Int] = None) = @{
    routes.GoodController.list(newPage, newOrderBy.map { orderBy =>
        if(orderBy == scala.math.abs(currentOrderBy)) -currentOrderBy else orderBy
    }.getOrElse(currentOrderBy), currentFilter)

}

@**********************************
* Helper generating table headers *
***********************************@
@header(orderBy: Int, title: String) = {
    <th class="col@orderBy header @if(scala.math.abs(currentOrderBy) == orderBy) @{if(currentOrderBy < 0) "headerSortDown" else "headerSortUp"}">
        <a href="@link(0, Some(orderBy))">@title</a>
    </th>
}

@main("Good List database") {
    @Option(currentPage.items).filterNot(_.isEmpty).map { goods =>

    <table class="computers zebra-striped">
        <thead>
            <tr>
                @header(2, "Good")
                @header(3, "Name")
                @header(4, "Price")
                @header(5, "Cost")
            </tr>
        </thead>
        <tbody>

        @goods.map { good => {
                <tr>
                    <td></td>
                    <td>
                    @good.name
                    </td>
                    <td>
                    @good.price
                    </td>
                    <td>
                    @good.cost
                    </td>
                </tr>
            }
        }

        </tbody>
    </table>

    <div id="pagination" class="pagination">
        <ul>
            @currentPage.prev.map { page =>
            <li class="prev">
                <a href="@link(page)">&larr; Previous</a>
            </li>
            }.getOrElse {
                <li class="prev disabled">
                    <a>&larr; Previous</a>
                </li>
            }
        <li class="current">
            <a>Displaying @(currentPage.offset + 1) to @(currentPage.offset + goods.size) of @currentPage.total</a>
        </li>
            @currentPage.next.map { page =>
            <li class="next">
                <a href="@link(page)">Next &rarr;</a>
            </li>
            }.getOrElse {
                <li class="next disabled">
                    <a>Next &rarr;</a>
                </li>
            }
        </ul>
    </div>

    }.getOrElse {

        <div class="well">
            <em>Nothing to display</em>
        </div>

    }
}